package com.company.Sort;

import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}12:35
 */
public class selectSort {
    public static void main(String[] args) {
        int[] arr = {101,34,110,1,2,5};
        selectSort(arr);
    }

    public static void selectSort(int[] arr){
        boolean flag = true;
        for (int i = 0; i < arr.length; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
                if (min < arr[j]) {
                    min = arr[j];
                    minIndex = j;//重置minIndex
                }
            }
            if (minIndex!=i) {//交换
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
